func bfs(i, j, rows, cols int, matrix *[][]int) {
	if (*matrix)[i][j] == 0 {
		(*matrix)[i][j] = 2
		if i+1 < rows && j+1 >= cols {
			bfs(i+1, j, rows, cols, matrix)
		} else if i+1 >= rows && j+1 < cols {
			bfs(i, j+1, rows, cols, matrix)
		} else if i+1 < rows && j+1 < cols {
			bfs(i, j+1, rows, cols, matrix)
			bfs(i+1, j, rows, cols, matrix)
		}
	}
}

func movingCount(threshold, rows, cols int) int {
	if rows == 0 || cols == 0 {
		return 0
	}
	var matrix [][]int = make([][]int, 0)
	for i := 0; i < rows; i++ {
		var arr []int = make([]int, 0)
		for j := 0; j < cols; j++ {
			if i/10+i%10+j/10+j%10 <= threshold {
				arr = append(arr, 0)
			} else {
				arr = append(arr, 1)
			}
		}
		matrix = append(matrix, arr)
	}

	// BFS
	bfs(0, 0, rows, cols, &matrix)

	// count
	var cnt int = 0
	for i := 0; i < rows; i++ {
		for j := 0; j < cols; j++ {
			if matrix[i][j] == 2 {
				cnt++
			}
		}
	}
	return cnt
}